package cn.itcast.web.controller.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
    自定义一个异常处理器，必须继承HandlerExceptionResolver接口

 */
@Component
public class SaasExecptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
       //创建一个ModelAndView
        ModelAndView mv = new ModelAndView();

        mv.setViewName("error");

        mv.addObject("errorMsg",ex.getMessage());

        ex.printStackTrace();
        return mv;
    }
}
